package ru.ifmo.croak.impl.remoting.post.team2.client;

import ru.ifmo.croak.api.Message;
import ru.ifmo.croak.api.PostService;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: Евгений
 * Date: 18.05.11
 * Time: 16:17
 * To change this template use File | Settings | File Templates.
 */
public class PostServiceImpl implements PostService {
    private final String name;
    private final Logger log;
    private String [] hosts;
    private MessageSender messageSender;
    private MessageDumper messageDumper;
    private ConcurrentLinkedQueue<Message> waitingBuffer;
    public PostServiceImpl (String name) {
        messageSender = new MessageSender(name);
        //messageDumper = new MessageDumper(name+"_messageDumper", "/dumps" ,messageSender);
        messageSender.start();
        waitingBuffer = new ConcurrentLinkedQueue<Message>();
        this.name = name;
        log = Logger.getLogger(name);

    }

    public void postMessage(Message message) {
        try
        {
            messageSender.addMessage(message);
            //messageDumper.addMessage(message);

        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
